﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Transaction.Interceptor;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;
using OpenSda.Agilcont.Common.Business.Contracts;

namespace OpenSda.Agilcont.Common.Business.SfContexts
{
public class UserBusiness : IUserBusiness {

        IUserData userData;
        IAgenciaData agenciaData;

        public IUserData UserData { set { userData = value; } }
        public IAgenciaData AgenciaData { set { agenciaData = value; } }
  

        [Transaction]
        public User Save(User user)
        {
            if (user == null) 
                throw new UserCannotBeNullException();
            // Não permitir duplicar Name
            //if (userData.GetAllQueryable().Where(ms => ms.Identity != user.Identity && ms.Name == user.Name).Count() > 0)
            //    throw new UserNameInUseException();

            // Não permitir duplicar RazonSocial
            //if (userData.GetAllQueryable().Where(ms => ms.Identity != user.Identity && ms.UserLogin == user.UserLogin).Count() > 0)
            //    throw new UserUserLoginInUseException();

            return userData.Save(user);

            
        }
        
        public User GetByid(Guid guid)  {
        //user.Identity == Guid.Empty
        return userData.Select(guid);
       }

    //   public void delete(User user)  {
     
      
    //}




    }
}


